<?php
// +----------------------------------------------------------------------
// | xiongrui [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.xiongrui.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.xiongrui.cn>
// +----------------------------------------------------------------------
namespace app\common\model;


class Cart extends Base{

  protected $type       = [
         'create_time' => 'timestamp:Y/m/d h:i:s',
  ];

  public static function getNumAndPrice($map){
    $cartlist = Cart::all($map);
    $arr = array();$arr['num']=0;$arr['price']=0;$arr['good_id_arr']=array();$arr['list']= $cartlist;$arr['pack_price']=0;
    $arr['freight_art_price']=0;
    $phone = db('WxUser')->where('id', USER_ID)->value('phone');


  	foreach ($cartlist as $key=>$list) {
  		$arr['num'] += $list->num;

  		$arr['good_id_arr'][$key] = $list->good_id;
      $arr['rule_id_arr'][$list->num] = $list->rule_id;
      $arr['goods_feature'][$key] = $list->goods_feature;
      if($list->goods_feature != 5){
        $arr['freight_art_price'] += $list->good_price*$list->num;
      }
      //如何是会员
      if($phone && $list->goods_feature != 5 && $list->goods_feature != 0){
        $arr['price'] += $list->good_price*$list->num*config('member_discount');
      }else{
        $arr['price'] += $list->good_price*$list->num;
      }

      //打包费用
      $pprice = db('goodsrule')->where('id', $list->rule_id)->value('pack_price');
      $arr['pack_price'] +=  $list->num*$pprice;
  	}

    if(is_array($arr['goods_feature'])){
      $arr['goods_feature'] = array_unique($arr['goods_feature']);
    }

  	return $arr;
  }
}
